

var _page = $('.page')

var thisload1 = bottlecms.load({
    elem: $('.infinite-chat1'),
    scroll: $('.infinite-scroll1'),
    done: function(page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function(data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(chat_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})

var thisload2 = bottlecms.load({
    elem: $('.infinite-chat2'),
    scroll: $('.infinite-scroll2'),
    done: function(page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function(data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(friend_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})

var tabload = function(){
    setTimeout(function() {
        if($('.bcui-tab .bcui-tab-content .item.active .infinite-chat1').length>0){
            thisload1.init();
        }
        else if($('.bcui-tab .bcui-tab-content .item.active .infinite-chat2').length>0){
            thisload2.init();
        }
    }, 100)
}

$(_page).on('click', '.bcui-tab .bcui-tab-title .item', function(event) {
    tabload();
});
tabload();


// /*聊天列表*/
function chat_template(v) {
    var html = "";
    html += '<a  target="_blank" href="/center/chat/info/'+v.userId+'" class="item" data-uid="' + v.userId + '">';
    html += '<div class="picbox"><img class="pic" src="' + v.photo + '_200x200.jpg"></div>';
    html += '<div class="uinfo"><div class="nickname">' + v.nickname + '</div><div class="conversation">' + v.msgTitle + '</div></div>';
    html += '<div class="etime">' + (v.createTime) + '</div>';
    if (v.unreadNum > 0) html += '<div class="unreadNum">' + v.unreadNum + '</div>';
    html += '<div class="editbox"><div class="_cp del" data-uid="' + v.userId + '">删除</div></div>';
    html += '</a>';
    return html;
}





/*朋友列表*/
function friend_template(v) {
    var html = '<div class="item ub">';
    html += '<a class="ub-f1"   target="_blank" href="/center/chat/info/'+v.userId+'">';
    html += '<div class="picbox"><img photo_mode="' + v.photoMode + '" src="' + v.photo + '_200x200.jpg"></div>';
    html += '<div class="uinfo"><div class="nickname">' + v.nickname + '</div></div>';
    html += '</a>';
    html+='<div class="ub toolbar"><div>查看资料</div><div>删除好友</div></div>';
    html += '</div>';
    return html;
}
/*新朋友列表*/
function friend_apply_template(v) {
    var html = "";
    html += '<div class="item ub ub-ac" status="' + v.isAuth + '">';
    if (v.single) {
        html += '    <a   class="ub ub-f1 "  href="/single/info/' + v.userId + '">';
        html += '    <div class="ub-img1"  photo_mode="' + v.photoMode + '" style="background-image:url(' + v.photo + '_200x200.jpg)"></div>';
        html += '    <div class="ub-f1 info">';
        html += '        <div class="nickname">' + v.nickname + ' <span class="gender_' + v.gender + '"></span></div>';
        html += '        <p class="info"> ';
        if (v.districtCn) {
            html += '            <span class="district">' + v.districtCn + '</span> ';
        }
        html += '            ' + v.age + '岁 ';
        if (v.height) {
            html += '            . ' + v.height + 'cm ';
        }
        if (v.constellationCn) {
            html += '            . ' + v.constellationCn + ' ';
        }
        html += '        </p>';
        html += '    </div>';
        html += '    </a>';
    } else {
        html += '    <div  class="ub ub-f1 empty">用户不存在或已删除</div>';
    }

    html += '    <div class="btnbox _dc">';
    html += '       <div class="status_3 group-btn group-btn-sm">';
    html += '           <span class="btn btn-info js_agree" data-id="' + v.userId + '">同意</span>';
    html += '           <span class="btn btn-danger js_refuse" data-id="' + v.userId + '">拒绝</span>';
    html += '       </div>';
    html += '       <div class="status_1">已同意</div>';
    html += '       <div class="status_2">已拒绝</div>';
    html += '       <div class="status_4">已超时</div>';
    html += '    </div>';
    html += '</div>';
    return html;
}
